﻿namespace Smart.ERP
{
    using Smart.Data.Helper;
    using Smart.Utils.Lib;
    using System;
    using System.Data;
    using System.Data.SqlClient;
    using System.Windows.Forms;

    public class STOCK
    {
        private bool m_Active;
        private string m_Address;
        private string m_Contact;
        private string m_Description;
        private string m_Email;
        private string m_Fax;
        private string m_Manager;
        private string m_Mobi;
        private string m_Stock_ID;
        private string m_Stock_Name;
        private string m_Telephone;

        public STOCK()
        {
            this.m_Stock_ID = "";
            this.m_Stock_Name = "";
            this.m_Contact = "";
            this.m_Address = "";
            this.m_Email = "";
            this.m_Telephone = "";
            this.m_Fax = "";
            this.m_Mobi = "";
            this.m_Manager = "";
            this.m_Description = "";
            this.m_Active = true;
        }

        public STOCK(string Stock_ID, string Stock_Name, string Contact, string Address, string Email, string Telephone, string Fax, string Mobi, string Manager, string Description, bool Active)
        {
            this.m_Stock_ID = Stock_ID;
            this.m_Stock_Name = Stock_Name;
            this.m_Contact = Contact;
            this.m_Address = Address;
            this.m_Email = Email;
            this.m_Telephone = Telephone;
            this.m_Fax = Fax;
            this.m_Mobi = Mobi;
            this.m_Manager = Manager;
            this.m_Description = Description;
            this.m_Active = Active;
        }

        public void AddCombo(ComboBox combo)
        {
            MyLib.TableToComboBox(combo, this.GetList(), "STOCK_Name", "STOCK_ID");
        }

        public void AddComboAll(ComboBox combo)
        {
            DataTable list = new DataTable();
            list = this.GetList();
            DataRow row = list.NewRow();
            row["STOCK_ID"] = "All";
            row["STOCK_Name"] = "Tất cả";
            list.Rows.InsertAt(row, 0);
            MyLib.TableToComboBox(combo, list, "STOCK_Name", "STOCK_ID");
        }

        public string Delete()
        {
            string[] myParams = new string[] { "@Stock_ID" };
            object[] myValues = new object[] { this.m_Stock_ID };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("STOCK_Delete", myParams, myValues);
        }

        public string Delete(string Stock_ID)
        {
            string[] myParams = new string[] { "@Stock_ID" };
            object[] myValues = new object[] { Stock_ID };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("STOCK_Delete", myParams, myValues);
        }

        public string Delete(SqlConnection myConnection, string Stock_ID)
        {
            string[] myParams = new string[] { "@Stock_ID" };
            object[] myValues = new object[] { Stock_ID };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myConnection, "STOCK_Delete", myParams, myValues);
        }

        public string Delete(SqlTransaction myTransaction, string Stock_ID)
        {
            string[] myParams = new string[] { "@Stock_ID" };
            object[] myValues = new object[] { Stock_ID };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "STOCK_Delete", myParams, myValues);
        }

        public bool Exist(string Stock_ID)
        {
            string[] strArray = new string[] { "@Stock_ID" };
            object[] objArray = new object[] { Stock_ID };
            SqlHelper helper = new SqlHelper();
            return false;
        }

        public bool Exist(SqlTransaction myTransaction, string Stock_ID)
        {
            bool hasRows = false;
            string[] myParams = new string[] { "@Stock_ID" };
            object[] myValues = new object[] { Stock_ID };
            SqlDataReader reader = new SqlHelper().ExecuteReader(myTransaction, "STOCK_Get", myParams, myValues);
            if (reader != null)
            {
                hasRows = reader.HasRows;
                reader.Close();
                reader.Dispose();
            }
            return hasRows;
        }

        public bool ExistByName(string Stock_Name)
        {
            bool hasRows = false;
            string[] myParams = new string[] { "@Stock_Name" };
            object[] myValues = new object[] { Stock_Name };
            SqlHelper helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader("STOCK_GetByName", myParams, myValues);
            if (reader != null)
            {
                hasRows = reader.HasRows;
                reader.Close();
                helper.Close();
                reader = null;
            }
            return hasRows;
        }

        public bool ExistByName(SqlTransaction myTransaction, string Stock_Name)
        {
            bool hasRows = false;
            string[] myParams = new string[] { "@Stock_Name" };
            object[] myValues = new object[] { Stock_Name };
            SqlDataReader reader = new SqlHelper().ExecuteReader(myTransaction, "STOCK_GetByName", myParams, myValues);
            if (reader != null)
            {
                hasRows = reader.HasRows;
                reader.Close();
            }
            return hasRows;
        }

        public string Get(string Stock_ID)
        {
            string str = "";
            string[] myParams = new string[] { "@Stock_ID" };
            object[] myValues = new object[] { Stock_ID };
            SqlHelper helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader("STOCK_Get", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    this.m_Stock_ID = Convert.ToString(reader["Stock_ID"]);
                    this.m_Stock_Name = Convert.ToString(reader["Stock_Name"]);
                    this.m_Contact = Convert.ToString(reader["Contact"]);
                    this.m_Address = Convert.ToString(reader["Address"]);
                    this.m_Email = Convert.ToString(reader["Email"]);
                    this.m_Telephone = Convert.ToString(reader["Telephone"]);
                    this.m_Fax = Convert.ToString(reader["Fax"]);
                    this.m_Mobi = Convert.ToString(reader["Mobi"]);
                    this.m_Manager = Convert.ToString(reader["Manager"]);
                    this.m_Description = Convert.ToString(reader["Description"]);
                    this.m_Active = Convert.ToBoolean(reader["Active"]);
                    str = "OK";
                }
                reader.Close();
                helper.Close();
                reader = null;
            }
            return str;
        }

        public string Get(SqlConnection myConnection, string Stock_ID)
        {
            string str = "";
            string[] myParams = new string[] { "@Stock_ID" };
            object[] myValues = new object[] { Stock_ID };
            SqlHelper helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader(myConnection, "STOCK_Get", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    this.m_Stock_ID = Convert.ToString(reader["Stock_ID"]);
                    this.m_Stock_Name = Convert.ToString(reader["Stock_Name"]);
                    this.m_Contact = Convert.ToString(reader["Contact"]);
                    this.m_Address = Convert.ToString(reader["Address"]);
                    this.m_Email = Convert.ToString(reader["Email"]);
                    this.m_Telephone = Convert.ToString(reader["Telephone"]);
                    this.m_Fax = Convert.ToString(reader["Fax"]);
                    this.m_Mobi = Convert.ToString(reader["Mobi"]);
                    this.m_Manager = Convert.ToString(reader["Manager"]);
                    this.m_Description = Convert.ToString(reader["Description"]);
                    this.m_Active = Convert.ToBoolean(reader["Active"]);
                    str = "OK";
                }
                reader.Close();
                helper.Close();
                reader = null;
            }
            return str;
        }

        public string Get(SqlTransaction myTransaction, string Stock_ID)
        {
            string str = "";
            string[] myParams = new string[] { "@Stock_ID" };
            object[] myValues = new object[] { Stock_ID };
            SqlHelper helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader(myTransaction, "STOCK_Get", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    this.m_Stock_ID = Convert.ToString(reader["Stock_ID"]);
                    this.m_Stock_Name = Convert.ToString(reader["Stock_Name"]);
                    this.m_Contact = Convert.ToString(reader["Contact"]);
                    this.m_Address = Convert.ToString(reader["Address"]);
                    this.m_Email = Convert.ToString(reader["Email"]);
                    this.m_Telephone = Convert.ToString(reader["Telephone"]);
                    this.m_Fax = Convert.ToString(reader["Fax"]);
                    this.m_Mobi = Convert.ToString(reader["Mobi"]);
                    this.m_Manager = Convert.ToString(reader["Manager"]);
                    this.m_Description = Convert.ToString(reader["Description"]);
                    this.m_Active = Convert.ToBoolean(reader["Active"]);
                    str = "OK";
                }
                reader.Close();
                helper.Close();
            }
            return str;
        }

        public string GetByName(string Stock_Name)
        {
            string str = "";
            string[] myParams = new string[] { "@Stock_Name" };
            object[] myValues = new object[] { Stock_Name };
            SqlHelper helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader("STOCK_GetByName", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    this.m_Stock_ID = Convert.ToString(reader["Stock_ID"]);
                    this.m_Stock_Name = Convert.ToString(reader["Stock_Name"]);
                    this.m_Contact = Convert.ToString(reader["Contact"]);
                    this.m_Address = Convert.ToString(reader["Address"]);
                    this.m_Email = Convert.ToString(reader["Email"]);
                    this.m_Telephone = Convert.ToString(reader["Telephone"]);
                    this.m_Fax = Convert.ToString(reader["Fax"]);
                    this.m_Mobi = Convert.ToString(reader["Mobi"]);
                    this.m_Manager = Convert.ToString(reader["Manager"]);
                    this.m_Description = Convert.ToString(reader["Description"]);
                    this.m_Active = Convert.ToBoolean(reader["Active"]);
                    str = "OK";
                }
                reader.Close();
            }
            helper.Close();
            return str;
        }

        public string GetByName(SqlTransaction myTransaction, string Stock_Name)
        {
            string str = "";
            string[] myParams = new string[] { "@Stock_Name" };
            object[] myValues = new object[] { Stock_Name };
            SqlDataReader reader = new SqlHelper().ExecuteReader(myTransaction, "STOCK_GetByName", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    this.m_Stock_ID = Convert.ToString(reader["Stock_ID"]);
                    this.m_Stock_Name = Convert.ToString(reader["Stock_Name"]);
                    this.m_Contact = Convert.ToString(reader["Contact"]);
                    this.m_Address = Convert.ToString(reader["Address"]);
                    this.m_Email = Convert.ToString(reader["Email"]);
                    this.m_Telephone = Convert.ToString(reader["Telephone"]);
                    this.m_Fax = Convert.ToString(reader["Fax"]);
                    this.m_Mobi = Convert.ToString(reader["Mobi"]);
                    this.m_Manager = Convert.ToString(reader["Manager"]);
                    this.m_Description = Convert.ToString(reader["Description"]);
                    this.m_Active = Convert.ToBoolean(reader["Active"]);
                    str = "OK";
                }
                reader.Close();
            }
            return str;
        }

        public DataTable GetList()
        {
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteDataTable("STOCK_GetList");
        }

        public string Insert()
        {
            string[] myParams = new string[] { "@Stock_ID", "@Stock_Name", "@Contact", "@Address", "@Email", "@Telephone", "@Fax", "@Mobi", "@Manager", "@Description", "@Active" };
            object[] myValues = new object[] { this.m_Stock_ID, this.m_Stock_Name, this.m_Contact, this.m_Address, this.m_Email, this.m_Telephone, this.m_Fax, this.m_Mobi, this.m_Manager, this.m_Description, this.m_Active };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("STOCK_Insert", myParams, myValues);
        }

        public string Insert(SqlTransaction myTransaction)
        {
            string[] myParams = new string[] { "@Stock_ID", "@Stock_Name", "@Contact", "@Address", "@Email", "@Telephone", "@Fax", "@Mobi", "@Manager", "@Description", "@Active" };
            object[] myValues = new object[] { this.m_Stock_ID, this.m_Stock_Name, this.m_Contact, this.m_Address, this.m_Email, this.m_Telephone, this.m_Fax, this.m_Mobi, this.m_Manager, this.m_Description, this.m_Active };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "STOCK_Insert", myParams, myValues);
        }

        public string Insert(string Stock_ID, string Stock_Name, string Contact, string Address, string Email, string Telephone, string Fax, string Mobi, string Manager, string Description, bool Active)
        {
            string[] myParams = new string[] { "@Stock_ID", "@Stock_Name", "@Contact", "@Address", "@Email", "@Telephone", "@Fax", "@Mobi", "@Manager", "@Description", "@Active" };
            object[] myValues = new object[] { Stock_ID, Stock_Name, Contact, Address, Email, Telephone, Fax, Mobi, Manager, Description, Active };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("STOCK_Insert", myParams, myValues);
        }

        public string Insert(SqlConnection myConnection, string Stock_ID, string Stock_Name, string Contact, string Address, string Email, string Telephone, string Fax, string Mobi, string Manager, string Description, bool Active)
        {
            string[] myParams = new string[] { "@Stock_ID", "@Stock_Name", "@Contact", "@Address", "@Email", "@Telephone", "@Fax", "@Mobi", "@Manager", "@Description", "@Active" };
            object[] myValues = new object[] { Stock_ID, Stock_Name, Contact, Address, Email, Telephone, Fax, Mobi, Manager, Description, Active };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myConnection, "STOCK_Insert", myParams, myValues);
        }

        public string Insert(SqlTransaction myTransaction, string Stock_ID, string Stock_Name, string Contact, string Address, string Email, string Telephone, string Fax, string Mobi, string Manager, string Description, bool Active)
        {
            this.m_Stock_ID = Stock_ID;
            string[] myParams = new string[] { "@Stock_ID", "@Stock_Name", "@Contact", "@Address", "@Email", "@Telephone", "@Fax", "@Mobi", "@Manager", "@Description", "@Active" };
            object[] myValues = new object[] { Stock_ID, Stock_Name, Contact, Address, Email, Telephone, Fax, Mobi, Manager, Description, Active };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "STOCK_Insert", myParams, myValues);
        }

        public string NewID()
        {
            return SqlHelper.GenCode("STOCK", "Stock_ID", "K");
        }

        public string NewID(SqlTransaction myTransaction)
        {
            return SqlHelper.GenCode(myTransaction, "STOCK", "Stock_ID", "K");
        }

        public string Update()
        {
            string[] myParams = new string[] { "@Stock_ID", "@Stock_Name", "@Contact", "@Address", "@Email", "@Telephone", "@Fax", "@Mobi", "@Manager", "@Description", "@Active" };
            object[] myValues = new object[] { this.m_Stock_ID, this.m_Stock_Name, this.m_Contact, this.m_Address, this.m_Email, this.m_Telephone, this.m_Fax, this.m_Mobi, this.m_Manager, this.m_Description, this.m_Active };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("STOCK_Update", myParams, myValues);
        }

        public string Update(SqlTransaction myTransaction)
        {
            string[] myParams = new string[] { "@Stock_ID", "@Stock_Name", "@Contact", "@Address", "@Email", "@Telephone", "@Fax", "@Mobi", "@Manager", "@Description", "@Active" };
            object[] myValues = new object[] { this.m_Stock_ID, this.m_Stock_Name, this.m_Contact, this.m_Address, this.m_Email, this.m_Telephone, this.m_Fax, this.m_Mobi, this.m_Manager, this.m_Description, this.m_Active };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "STOCK_Update", myParams, myValues);
        }

        public string Update(string Stock_ID, string Stock_Name, string Contact, string Address, string Email, string Telephone, string Fax, string Mobi, string Manager, string Description, bool Active)
        {
            string[] myParams = new string[] { "@Stock_ID", "@Stock_Name", "@Contact", "@Address", "@Email", "@Telephone", "@Fax", "@Mobi", "@Manager", "@Description", "@Active" };
            object[] myValues = new object[] { Stock_ID, Stock_Name, Contact, Address, Email, Telephone, Fax, Mobi, Manager, Description, Active };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("STOCK_Update", myParams, myValues);
        }

        public string Update(SqlConnection myConnection, string Stock_ID, string Stock_Name, string Contact, string Address, string Email, string Telephone, string Fax, string Mobi, string Manager, string Description, bool Active)
        {
            string[] myParams = new string[] { "@Stock_ID", "@Stock_Name", "@Contact", "@Address", "@Email", "@Telephone", "@Fax", "@Mobi", "@Manager", "@Description", "@Active" };
            object[] myValues = new object[] { Stock_ID, Stock_Name, Contact, Address, Email, Telephone, Fax, Mobi, Manager, Description, Active };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myConnection, "STOCK_Update", myParams, myValues);
        }

        public string Update(SqlTransaction myTransaction, string Stock_ID, string Stock_Name, string Contact, string Address, string Email, string Telephone, string Fax, string Mobi, string Manager, string Description, bool Active)
        {
            string[] myParams = new string[] { "@Stock_ID", "@Stock_Name", "@Contact", "@Address", "@Email", "@Telephone", "@Fax", "@Mobi", "@Manager", "@Description", "@Active" };
            object[] myValues = new object[] { Stock_ID, Stock_Name, Contact, Address, Email, Telephone, Fax, Mobi, Manager, Description, Active };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "STOCK_Update", myParams, myValues);
        }

        public bool Active
        {
            get
            {
                return this.m_Active;
            }
            set
            {
                this.m_Active = value;
            }
        }

        public string Address
        {
            get
            {
                return this.m_Address;
            }
            set
            {
                this.m_Address = value;
            }
        }

        public string Contact
        {
            get
            {
                return this.m_Contact;
            }
            set
            {
                this.m_Contact = value;
            }
        }

        public string Description
        {
            get
            {
                return this.m_Description;
            }
            set
            {
                this.m_Description = value;
            }
        }

        public string Email
        {
            get
            {
                return this.m_Email;
            }
            set
            {
                this.m_Email = value;
            }
        }

        public string Fax
        {
            get
            {
                return this.m_Fax;
            }
            set
            {
                this.m_Fax = value;
            }
        }

        public string Manager
        {
            get
            {
                return this.m_Manager;
            }
            set
            {
                this.m_Manager = value;
            }
        }

        public string Mobi
        {
            get
            {
                return this.m_Mobi;
            }
            set
            {
                this.m_Mobi = value;
            }
        }

        public string ProductName
        {
            get
            {
                return "Class STOCK";
            }
        }

        public string ProductVersion
        {
            get
            {
                return "1.0.0.0";
            }
        }

        public string Stock_ID
        {
            get
            {
                return this.m_Stock_ID;
            }
            set
            {
                this.m_Stock_ID = value;
            }
        }

        public string Stock_Name
        {
            get
            {
                return this.m_Stock_Name;
            }
            set
            {
                this.m_Stock_Name = value;
            }
        }

        public string Telephone
        {
            get
            {
                return this.m_Telephone;
            }
            set
            {
                this.m_Telephone = value;
            }
        }
    }
}

